package net.da.client.common.ui.widget;

import net.da.client.common.component.AbstractComponent;
import net.da.client.common.component.ComponentDispatcher;
import net.da.client.common.component.ComponentDispatcherImpl;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class NavigationPanel extends Composite {

	public NavigationPanel(final AbstractComponent component, String[] compNames) {
		
		if (compNames == null) {
			compNames = new String[]{};
		}

		HorizontalPanel hp = new HorizontalPanel();
		initWidget(hp);		
		for (int i = 0; i < compNames.length; i++) {
			final String name = compNames[i];
			Button button = new Button(name);
			if (name.equals(component.getComponentDef().getName())) {
				button.setEnabled(false);
			}
			button.addClickListener(new ClickListener() {

				public void onClick(Widget sender) {
					onButtonClick(name);
				}
			});
			hp.add(button);
		}
	}

	public void onButtonClick(String compName) {
		ComponentDispatcher dispatcher = ComponentDispatcherImpl.getInstance();
		dispatcher.jumpTo(compName);
	}

}
